package com.tianji.learning.task;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DemoTask {

    @XxlJob("demoJobHandler")
    public ReturnT<String> demoJobHandler(){
        log.info("demoJobHandler start");
        return ReturnT.SUCCESS;
    }

    @XxlJob("shardingJobHandler")
    public ReturnT<String> shardingJobHandler(){
        // 总的节点数
        int shardTotal = XxlJobHelper.getShardTotal();
        // 当前节点的索引
        int shardIndex = XxlJobHelper.getShardIndex();
        // 执行分片任务
        // zset数据同步到数据库，假设：zset中有100万行记录,100条一页，总共10000页
        //0: 0 3 6 9 ....
        //1: 1 4 7 10 ...
        //2: 2 5 8 11 ..
        log.info("shardTotal:{} shardIndex:{}", shardTotal, shardIndex);
        return ReturnT.SUCCESS;
    }
}
